package com.stu.management.service.impl;


import com.stu.management.mapper.MenuMapper;
import com.stu.management.pojo.Menu;
import com.stu.management.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuMapper menuDao;

    public List<Menu> getMenuList() {
        List<Menu> menuList = menuDao.selectByExample(null);//未分一二级
        List<Menu> newMenuList = new ArrayList<>();//保存分级以后的菜单
        for (Menu menu : menuList) {
            if (menu.getUpmenuid() == 0) { //说明是一级菜单
                List<Menu> secondList = new ArrayList<>();
                for (Menu second : menuList) {
                    if (second.getUpmenuid() == menu.getMenuid()) {
                        secondList.add(second);
                    }
                }
                menu.setSecondMenuList(secondList);
                newMenuList.add(menu);
            }
        }


        return newMenuList;
    }
}
